package com.wn.manpower.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.wn.common.PageBean;
import com.wn.entity.Dimission;
import com.wn.entity.Hr;
import com.wn.entity.OfficeSupplies;
import com.wn.entity.Recipients;
import com.wn.manpower.mapper.DimissionMapper;
import com.wn.manpower.mapper.OfficeSuppliesMapper;
import com.wn.manpower.mapper.RecipientsMapper;
import com.wn.manpower.service.DimissionService;
import com.wn.manpower.service.RecipientsService;
import com.wn.utils.PageBeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author dzj
 * date: 2022/10/20
 */
@Service
public class RecipientsServiceImp implements RecipientsService {

    @Autowired
    private RecipientsMapper recipientsMapper;

    @Autowired
    private OfficeSuppliesMapper officeSuppliesMapper;

    @Override
    public void add(Recipients recipients) {
        OfficeSupplies officeSupplies=new OfficeSupplies();
        officeSupplies.setName(recipients.getOfficeSupplies().getName());
        List<OfficeSupplies> officeSuppliesList = officeSuppliesMapper.getByCondition(officeSupplies);
        officeSupplies.setId(officeSuppliesList.get(0).getId());
        recipients.setOfficeSupplies(officeSupplies);
        recipientsMapper.add(recipients);
    }

    @Override
    public void update(Recipients recipients) {
        OfficeSupplies officeSupplies=new OfficeSupplies();
        officeSupplies.setName(recipients.getOfficeSupplies().getName());
        List<OfficeSupplies> officeSuppliesList = officeSuppliesMapper.getByCondition(officeSupplies);
        officeSupplies.setId(officeSuppliesList.get(0).getId());
        recipients.setOfficeSupplies(officeSupplies);
        recipientsMapper.update(recipients);
    }

    @Override
    public void del(int id) {
        recipientsMapper.del(id);
    }

    @Override
    public Recipients getById(int id) {
        return recipientsMapper.getById(id);
    }

    @Override
    public Recipients getByActivitiInstanceId(String activitiInstanceId) {
        return recipientsMapper.getByActivitiInstanceId(activitiInstanceId);
    }

    @Override
    public PageBean<Recipients> getPageByCondition(Recipients recipients, int currPage, int pageSize) {
        Page<Object> page = PageHelper.startPage(currPage, pageSize);
        List<Recipients> recipients1 = recipientsMapper.getByCondition(recipients);
        PageBean<Recipients> pageBean = PageBeanUtil.getPageBean(recipients1, page, currPage, pageSize);
        return pageBean;
    }
}
